package com.gitee.wsl.platform.scheduler

import com.gitee.wsl.concurrent.scheduler.Scheduler
import com.gitee.wsl.concurrent.scheduler.sample.TrampolineScheduler
import kotlin.time.Duration.Companion.milliseconds

actual fun createTrampolineScheduler(): Scheduler =
    TrampolineScheduler(
        sleep = {
            try {
                Thread.sleep(
                    it.inWholeMilliseconds,
                    (it.inWholeNanoseconds % 1.milliseconds.inWholeNanoseconds).toInt()
                )
                true
            } catch (e: InterruptedException) {
                Thread.currentThread().interrupt()
                false
            }
        }
    )
